package com.ld.security.user;

import jakarta.annotation.Nonnull;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/json/v1/user")
public class UserController {

    @GetMapping("/hello")
    public ResponseEntity<String> hello() {
        return ResponseEntity.ok("say hello!!!");
    }

    @GetMapping("/user/{id}")
    public ResponseEntity<String> getById(@Validated UserRequest request) {
        boolean code = request.isCode();
        Integer co = request.getCo();
        return ResponseEntity.ok(request.id + "");
    }

    /**
     * 记录类-简单的数据载体使用，所有字段为final，靠构造器进行声明字段，可以添加方法或静态方法
     *
     * @param id
     */
    public record UserRequest(@Nonnull Integer id) {

        boolean isCode() {
            return id > 0;
        }

        Integer getCo() {
            return id;
        }
    }
}
